package com.project.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.SuppliersBean;
import com.project.mapper.ISuppliersMapper;
import com.project.service.ISuppliersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class SupplierServiceImpl implements ISuppliersService {

    @Autowired
    private ISuppliersMapper mapper;

//    @Autowired
//    private IProductMapper productMapper;

    @Override
    public PageInfo<SuppliersBean> findByItem(int page, int pageSize, String suppliersName, String suppliersRange) {
        PageHelper.startPage(page,pageSize);
        return PageInfo.of(mapper.findByItem(suppliersName,suppliersRange));
    }

    @Override
    public SuppliersBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public boolean addSuppliers(SuppliersBean suppliers) {
        SuppliersBean suppliersBean =mapper.selectOne(
                new QueryWrapper<SuppliersBean>().eq("suppliersName",suppliers.getSuppliersName())
        );
        if (suppliersBean != null ){
            return  false;
        }
        mapper.addSuppliers(suppliers);
        return true;
    }

//    @Override
//    public void updateSuppliers(int id, String suppliersManager, String suppliersPhone) {
//        mapper.updateSuppliers(id, suppliersManager, suppliersPhone);
//    }

//    @Override
//    public List<SuppliersBean> findAll() {
//        List<SuppliersBean> supplierList = mapper.selectList(null);
////        for (SuppliersBean supplier: supplierList) {
////            supplier.setProductList(
////                    productMapper.selectList(
////                            new QueryWrapper<ProductBean>().eq("fk_supplierId",supplier.getId())));
////        }
//        return supplierList;
//    }

    @Override
    public void update(SuppliersBean supplier) {
        mapper.updateById(supplier);
    }


}
